/**
 * 发送短信验证码
 * Copyright (c) 2014 Jarvan
 * @author 2465884287@qq.com
 */
t = 120;
function countDown($obj) {
	var time = 0;
	if ($obj.attr("id") == "send") {
		time = --t;
		if (time <= 0) {
			t = 120;
			$obj[0].disabled = !$obj[0].disabled;
			clearInterval(inter);
			$obj.text("点击发送");
			return

		}
	}
	$obj.text(time + "s后重新发送");
}
$(function() {
	$(".cd").bind("click", function() {
		var mobile = $("#phone").val();
		$this = $(this);
		// 没有被禁用时禁用并执行倒计时
		$.post("/qiuzhi/SendCodeController", {
			mobile : mobile
		}, function(r) {
			if (r == "0") {
				alert("该手机已被注册");
			}else{
				alert("验证码发送成功");
				if (!$this[0].disabled) {
					$this[0].disabled = 'disabled';
					if ($this.attr("id") == "send") {
						inter = setInterval(function() {
							countDown($this);
						}, 1000);
					}
				}
			}
		});
	});
});